using System.Collections.Generic;
using System.IO;

namespace HappyTemplate
{
	public class SourceError
	{
		public readonly SourceLocation Location;
		public readonly string Message;

		public SourceError(SourceLocation loc, string message)
		{
			this.Location = loc;
			this.Message = message;
		}
		public override string ToString()
		{
			return StringHelp.Format("{0}: {1}", this.Location.ToString(), Message);
		}
	}

	public class SourceErrorCollection : List<SourceError>
	{


		public void PrintAll(TextWriter writer)
		{
			foreach (SourceError error in this)
				writer.WriteLine(error.ToString());
		}

		public void Add(SourceLocation loc, string msgfmt, params object[] args)
		{
			SourceError sec = new SourceError(loc, StringHelp.Format(msgfmt, args));
			this.Add(sec);
		}
	}
}
